package gui;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class PanelHovedmeny extends JPanel implements ActionListener{
	private JButton buttonNyBestilling, buttonKokk, buttonPizzabud, buttonAdmin, buttonAvslutt;
	private JLabel labelHovedmeny;
	private GridBagConstraints constraints;
	public PanelHovedmeny(){
		this.setLayout(new GridBagLayout());
		this.leggTilKnapper();
		GUI.getVindu().add(this);
	}
	private void leggTilKnapper(){
		buttonNyBestilling = new JButton("Ny bestilling");
		buttonNyBestilling.addActionListener(this);
		buttonKokk = new JButton("Kokk");
		buttonKokk.addActionListener(this);
		buttonPizzabud = new JButton("Pizzabud");
		buttonPizzabud.addActionListener(this);
		buttonAdmin = new JButton("Admin");
		buttonAdmin.addActionListener(this);
		buttonAvslutt = new JButton("Avslutt");
		buttonAvslutt.addActionListener(this);
		
		labelHovedmeny = new JLabel("Hovedmeny");
		Font font = new Font(labelHovedmeny.getFont().getFontName(),labelHovedmeny.getFont().getStyle(),30);
		labelHovedmeny.setFont(font);
		
		constraints = new GridBagConstraints();
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.gridwidth = 4;
		this.add(labelHovedmeny,constraints);
		constraints.ipadx = 60;
		constraints.ipady = 30;
		constraints.insets = new Insets(100, 10, 10, 10);
		constraints.gridy = 1;
		constraints.gridwidth = 1;
		this.add(buttonNyBestilling,constraints);
		constraints.gridx = 1;
		this.add(buttonKokk,constraints);
		constraints.gridx = 2;
		this.add(buttonPizzabud,constraints);
		constraints.gridx = 3;
		this.add(buttonAdmin,constraints);
		constraints.gridy = 2;
		constraints.gridx = 0;
		constraints.gridwidth = 4;
		this.add(buttonAvslutt,constraints);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==buttonNyBestilling)
			buttonNyBestilling_actionPerformed(e);
		else if(e.getSource()==buttonKokk)
			buttonKokk_actionPerformed(e);
		else if(e.getSource()==buttonPizzabud)
			buttonPizzabud_actionPerformed(e);
		else if(e.getSource()==buttonAdmin)
			buttonAdmin_actionPerformed(e);
		else if(e.getSource()==buttonAvslutt)
			buttonAvslutt_actionPerformed(e);
		

	}
	private void buttonAvslutt_actionPerformed(ActionEvent e) {
		Object[] options = { "Ja", "Nei" };
		int svar = JOptionPane.showOptionDialog(null, "Vil du avslutte?", "Warning", 
		JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
		null, options, options[0]);
		if(svar == 0){
			System.exit(0);
		}
		
	}
	private void buttonNyBestilling_actionPerformed(ActionEvent e)
	{
		this.setVisible(false);
		new PanelKunde();
	}

	private void buttonKokk_actionPerformed(ActionEvent e)
	{
		this.setVisible(false);
		new PanelKokk();
	}

	private void buttonPizzabud_actionPerformed(ActionEvent e)
	{
		this.setVisible(false);
		new PanelPizzabud();
	}

	private void buttonAdmin_actionPerformed(ActionEvent e)
	{
		this.setVisible(false);
		new PanelAdmin();
	}
}
